// let textEl = document.querySelector('#text')

let saveEl = document.querySelector('.save') //  按钮
let imgsEl = document.querySelector('.imgs') //  图片文件
let namesEl = document.querySelector('.name_new') //  名字


let user = localStorage.user && JSON.parse(localStorage.user)
// console.log(user);

//   用户名获取
let mingZi = document.querySelector('.mingzi')
userName()
async function userName() {

    let res = await axios({
        method: 'GET',
        url: '/api/user',
        params: {
            userId: user.userId,
        }
    })
    let html = ''
    html += `
                ${res.data.data.username} 
            `
    mingZi.innerHTML = html
}

// 保存设置按钮点击事件

saveSettings()
async function saveSettings() {
    let res = await axios({
        methed: 'GET',
        url: '/api/user',
        params: {
            userId: user.userId,
        }
    })
    console.log(res);

    let html = ''
    html += `
    <img class="imgs" src="http://localhost:8000/${res.data.data.headphoto}" alt = "" >
    `
    imgsEl.innerHTML = html


    namesEl.innerHTML = `
          <input type = "text"
          id = "names"
          value = ${res.data.data.username} >

    `
}


// 成功，跳转至登陆
// location.href = '../lk/my-diary.html'